var currentPage = 1;
var pageSize = 10;
var totalCount = 0;
var totalPage = 1;

function showPage() {
    if (totalPage == 0) {
        totalPage = 1;
    }
    if (currentPage < 1) {
        currentPage = 1
    }
    $("#showPage").text(currentPage + "/" + totalPage);
}

function showInfo() {
    let name = $("#name").val().trim();
    let positionName = $("#positionName").val().trim();
    let experience = $("#experience").val().trim();
    let status = $("#status").val().trim();
    let rTime = $("#rTime").val().trim();

    $("#tal1").find("tr:gt(0)").find("td").html("&nbsp;");

    let jsonA = {
        name: name,
        positionName: positionName,
        experience: experience,
        status: status,
        rTime: rTime,
        currentPage: currentPage,
        pageSize: pageSize
    }

    $.ajaxSettings.async = false;

    $.getJSON("showMianShi", jsonA, function (data) {
        totalCount = data.total;
        totalPage = data.pages;

        $(data.list).each(function (i, v) {
            let xiala;
            let tiao = "<button type=\"button\" class=\"layui-btn\" onclick=\"messageById(" + v.resumeId + ")\">面试结果登记</button>&nbsp;&nbsp;<button type=\"button\" class=\"layui-btn layui-btn-danger\" onclick=\"shanchu1(" + v.resumeId + ",this)\">删除</button>";
            if (v.status == "存档") {
                xiala = "<div class=\"layui-input-inline\" style=\"display: block;\">\n" +
                    "<div class=\"layui-input-block\" style=\"margin-left: 0px;\">\n" +
                    "<select name=\"status\" lay-verify=\"\" id=\"status\" lay-filter=\"stat1\">\n" +
                    "<option value='" + v.interviewId + "' disabled='disabled'>请选择</option>\n" +
                    "<option value=\"存档\" selected='selected' disabled='disabled'>存档</option>\n" +
                    "</select>\n" +
                    "</div>\n" +
                    "</div>";
                tiao = "<button type=\"button\" class=\"layui-btn\" onclick=\"messageById(" + v.resumeId + ")\">明细</button>&nbsp;&nbsp;<button type=\"button\" class=\"layui-btn layui-btn-danger\" onclick=\"shanchu1(" + v.resumeId + ",this)\">删除</button>"
            }
            if (v.status == "推荐面试") {
                xiala = "<div class=\"layui-input-inline\" style=\"display: block;\">\n" +
                    "<div class=\"layui-input-block\" style=\"margin-left: 0px;\">\n" +
                    "<select name=\"status\" lay-verify=\"\" id=\"status\" lay-filter=\"b\">\n" +
                    "<option value='" + v.interviewId + "' disabled='disabled'>请选择</option>\n" +
                    "<option value=\"推荐面试\" selected='selected' disabled='disabled'>推荐面试</option>\n" +
                    "<option value=\"推荐二面\">推荐二面</option>\n" +
                    "<option value=\"推荐三面\" disabled='disabled'>推荐三面</option>\n" +
                    "<option value=\"建议录用\" disabled='disabled'>建议录用</option>\n" +
                    "</select>\n" +
                    "</div>\n" +
                    "</div>";
            }
            if (v.status == "推荐二面") {
                xiala = "<div class=\"layui-input-inline\" style=\"display: block;\">\n" +
                    "<div class=\"layui-input-block\" style=\"margin-left: 0px;\">\n" +
                    "<select name=\"status\" lay-verify=\"\" id=\"status\" lay-filter=\"b\">\n" +
                    "<option value='" + v.interviewId + "' disabled='disabled'>请选择</option>\n" +
                    "<option value=\"推荐面试\" disabled='disabled'>推荐面试</option>\n" +
                    "<option value=\"推荐二面\" selected='selected' disabled='disabled'>推荐二面</option>\n" +
                    "<option value=\"推荐三面\">推荐三面</option>\n" +
                    "<option value=\"建议录用\" disabled='disabled'>建议录用</option>\n" +
                    "</select>\n" +
                    "</div>\n" +
                    "</div>";
            }
            if (v.status == "推荐三面") {
                xiala = "<div class=\"layui-input-inline\" style=\"display: block;\">\n" +
                    "<div class=\"layui-input-block\" style=\"margin-left: 0px; \">\n" +
                    "<select name=\"status\" lay-verify=\"\" id=\"status\" lay-filter=\"b\">\n" +
                    "<option value='" + v.interviewId + "' disabled='disabled'>请选择</option>\n" +
                    "<option value=\"推荐面试\" disabled='disabled'>推荐面试</option>\n" +
                    "<option value=\"推荐二面\" disabled='disabled'>推荐二面</option>\n" +
                    "<option value=\"推荐三面\" selected='selected' disabled='disabled'>推荐三面</option>\n" +
                    "<option value=\"建议录用\">建议录用</option>\n" +
                    "</select>\n" +
                    "</div>\n" +
                    "</div>";
            }
            if (v.status == "建议录用") {
                xiala = "<div class=\"layui-input-inline\" style=\"display: block;\">\n" +
                    "<div class=\"layui-input-block\" style=\"margin-left: 0px;\">\n" +
                    "<select name=\"status\" lay-verify=\"\" id=\"status\" lay-filter=\"b\">\n" +
                    "<option value='" + v.interviewId + "' disabled='disabled'>请选择</option>\n" +
                    "<option value=\"推荐面试\" disabled='disabled'>推荐面试</option>\n" +
                    "<option value=\"推荐二面\" disabled='disabled'>推荐二面</option>\n" +
                    "<option value=\"推荐三面\" disabled='disabled'>推荐三面</option>\n" +
                    "<option value=\"建议录用\" selected='selected' disabled='disabled'>建议录用</option>\n" +
                    "</select>\n" +
                    "</div>\n" +
                    "</div>";
                tiao = "<button type=\"button\" class=\"layui-btn\" onclick=\"messageById(" + v.resumeId + ")\">明细</button>&nbsp;&nbsp;<button type=\"button\" class=\"layui-btn layui-btn-danger\" onclick=\"shanchu1(" + v.resumeId + ",this)\">删除</button>"
            }
            if (v.status == "删除") {
                xiala = "<div class=\"layui-input-inline\" style=\"display: block;\">\n" +
                    "<div class=\"layui-input-block\" style=\"margin-left: 0px;\">\n" +
                    "<select name=\"status\" lay-verify=\"\" id=\"status\" lay-filter=\"stat1\">\n" +
                    "<option value='" + v.interviewId + "' disabled='disabled'>请选择</option>\n" +
                    "<option value=\"删除\" selected='selected' disabled='disabled'>删除</option>\n" +
                    "</select>\n" +
                    "</div>\n" +
                    "</div>";
                tiao = "<button type=\"button\" class=\"layui-btn\" onclick=\"messageById(" + v.resumeId + ")\">明细</button>";
            }
            if (v.status == "录用") {
                xiala = "<div class=\"layui-input-inline\" style=\"display: block;\">\n" +
                    "<div class=\"layui-input-block\" style=\"margin-left: 0px;\">\n" +
                    "<select name=\"status\" lay-verify=\"\" id=\"status\" lay-filter=\"stat1\">\n" +
                    "<option value='" + v.interviewId + "' disabled='disabled'>请选择</option>\n" +
                    "<option value=\"录用\" selected='selected' disabled='disabled'>录用</option>\n" +
                    "</select>\n" +
                    "</div>\n" +
                    "</div>";
                tiao = "<button type=\"button\" class=\"layui-btn\" onclick=\"messageById(" + v.resumeId + ")\">明细</button>";
            }
            $("#tal1").find("tr").eq(i + 1).find("td").eq(0).text((currentPage - 1) * pageSize + 1 + i);
            $("#tal1").find("tr").eq(i + 1).find("td").eq(1).text(v.name);
            $("#tal1").find("tr").eq(i + 1).find("td").eq(2).text(v.sex);
            $("#tal1").find("tr").eq(i + 1).find("td").eq(3).text(v.school);
            $("#tal1").find("tr").eq(i + 1).find("td").eq(4).text(v.educationBackground);
            $("#tal1").find("tr").eq(i + 1).find("td").eq(5).text(v.major);
            $("#tal1").find("tr").eq(i + 1).find("td").eq(6).text(v.positionName);
            $("#tal1").find("tr").eq(i + 1).find("td").eq(7).text(v.experience);
            $("#tal1").find("tr").eq(i + 1).find("td").eq(8).text(v.rTime);
            $("#tal1").find("tr").eq(i + 1).find("td").eq(9).html(xiala);
            $("#tal1").find("tr").eq(i + 1).find("td").eq(10).html(tiao);
        })

    })
    $.ajaxSettings.async = true;
    showPage();
    layui.use('form', function () {
        var form = layui.form;
        form.render();
    });
}

function showInfo1() {
    let name = $("#name").val().trim();
    let positionName = $("#positionName").val().trim();
    let experience = $("#experience").val().trim();
    let status = $("#status").val().trim();
    let rTime = $("#rTime").val().trim();

    $("#tal1").find("tr:gt(0)").find("td").html("&nbsp;");

    let jsonA = {
        name: name,
        positionName: positionName,
        experience: experience,
        status: status,
        rTime: rTime,
        currentPage: currentPage,
        pageSize: pageSize
    }

    $.ajaxSettings.async = false;

    $.getJSON("showMianShi1", jsonA, function (data) {
        totalCount = data.total;
        totalPage = data.pages;

        $(data.list).each(function (i, v) {
            let xiala;
            let tiao = "<button type=\"button\" class=\"layui-btn\" onclick=\"messageById(" + v.resumeId + ")\">面试结果登记</button>&nbsp;&nbsp;<button type=\"button\" class=\"layui-btn layui-btn-danger\" onclick=\"shanchu1(" + v.resumeId + ",this)\">删除</button>";
            if (v.status == "存档") {
                xiala = "<div class=\"layui-input-inline\" style=\"display: block;\">\n" +
                    "<div class=\"layui-input-block\" style=\"margin-left: 0px;\">\n" +
                    "<select name=\"status\" lay-verify=\"\" id=\"status\" lay-filter=\"stat1\">\n" +
                    "<option value='" + v.interviewId + "' disabled='disabled'>请选择</option>\n" +
                    "<option value=\"存档\" selected='selected' disabled='disabled'>存档</option>\n" +
                    "</select>\n" +
                    "</div>\n" +
                    "</div>";
                tiao = "<button type=\"button\" class=\"layui-btn\" onclick=\"messageById(" + v.resumeId + ")\">明细</button>&nbsp;&nbsp;<button type=\"button\" class=\"layui-btn layui-btn-danger\" onclick=\"shanchu1(" + v.resumeId + ",this)\">删除</button>"
            }
            if (v.status == "推荐面试") {
                xiala = "<div class=\"layui-input-inline\" style=\"display: block;\">\n" +
                    "<div class=\"layui-input-block\" style=\"margin-left: 0px;\">\n" +
                    "<select name=\"status\" lay-verify=\"\" id=\"status\" lay-filter=\"b\">\n" +
                    "<option value='" + v.interviewId + "' disabled='disabled'>请选择</option>\n" +
                    "<option value=\"推荐面试\" selected='selected' disabled='disabled'>推荐面试</option>\n" +
                    "<option value=\"推荐二面\">推荐二面</option>\n" +
                    "<option value=\"推荐三面\" disabled='disabled'>推荐三面</option>\n" +
                    "<option value=\"建议录用\" disabled='disabled'>建议录用</option>\n" +
                    "</select>\n" +
                    "</div>\n" +
                    "</div>";
            }
            if (v.status == "推荐二面") {
                xiala = "<div class=\"layui-input-inline\" style=\"display: block;\">\n" +
                    "<div class=\"layui-input-block\" style=\"margin-left: 0px;\">\n" +
                    "<select name=\"status\" lay-verify=\"\" id=\"status\" lay-filter=\"b\">\n" +
                    "<option value='" + v.interviewId + "' disabled='disabled'>请选择</option>\n" +
                    "<option value=\"推荐面试\" disabled='disabled'>推荐面试</option>\n" +
                    "<option value=\"推荐二面\" selected='selected' disabled='disabled'>推荐二面</option>\n" +
                    "<option value=\"推荐三面\">推荐三面</option>\n" +
                    "<option value=\"建议录用\" disabled='disabled'>建议录用</option>\n" +
                    "</select>\n" +
                    "</div>\n" +
                    "</div>";
            }
            if (v.status == "推荐三面") {
                xiala = "<div class=\"layui-input-inline\" style=\"display: block;\">\n" +
                    "<div class=\"layui-input-block\" style=\"margin-left: 0px; \">\n" +
                    "<select name=\"status\" lay-verify=\"\" id=\"status\" lay-filter=\"b\">\n" +
                    "<option value='" + v.interviewId + "' disabled='disabled'>请选择</option>\n" +
                    "<option value=\"推荐面试\" disabled='disabled'>推荐面试</option>\n" +
                    "<option value=\"推荐二面\" disabled='disabled'>推荐二面</option>\n" +
                    "<option value=\"推荐三面\" selected='selected' disabled='disabled'>推荐三面</option>\n" +
                    "<option value=\"建议录用\">建议录用</option>\n" +
                    "</select>\n" +
                    "</div>\n" +
                    "</div>";
            }
            if (v.status == "建议录用") {
                xiala = "<div class=\"layui-input-inline\" style=\"display: block;\">\n" +
                    "<div class=\"layui-input-block\" style=\"margin-left: 0px;\">\n" +
                    "<select name=\"status\" lay-verify=\"\" id=\"status\" lay-filter=\"b\">\n" +
                    "<option value='" + v.interviewId + "' disabled='disabled'>请选择</option>\n" +
                    "<option value=\"推荐面试\" disabled='disabled'>推荐面试</option>\n" +
                    "<option value=\"推荐二面\" disabled='disabled'>推荐二面</option>\n" +
                    "<option value=\"推荐三面\" disabled='disabled'>推荐三面</option>\n" +
                    "<option value=\"建议录用\" selected='selected' disabled='disabled'>建议录用</option>\n" +
                    "</select>\n" +
                    "</div>\n" +
                    "</div>";
                tiao = "<button type=\"button\" class=\"layui-btn\" onclick=\"messageById(" + v.resumeId + ")\">明细</button>&nbsp;&nbsp;<button type=\"button\" class=\"layui-btn layui-btn-danger\" onclick=\"shanchu1(" + v.resumeId + ",this)\">删除</button>"
            }
            if (v.status == "删除") {
                xiala = "<div class=\"layui-input-inline\" style=\"display: block;\">\n" +
                    "<div class=\"layui-input-block\" style=\"margin-left: 0px;\">\n" +
                    "<select name=\"status\" lay-verify=\"\" id=\"status\" lay-filter=\"stat1\">\n" +
                    "<option value='" + v.interviewId + "' disabled='disabled'>请选择</option>\n" +
                    "<option value=\"删除\" selected='selected' disabled='disabled'>删除</option>\n" +
                    "</select>\n" +
                    "</div>\n" +
                    "</div>";
                tiao = "<button type=\"button\" class=\"layui-btn\" onclick=\"messageById(" + v.resumeId + ")\">明细</button>";
            }
            if (v.status == "录用") {
                xiala = "<div class=\"layui-input-inline\" style=\"display: block;\">\n" +
                    "<div class=\"layui-input-block\" style=\"margin-left: 0px;\">\n" +
                    "<select name=\"status\" lay-verify=\"\" id=\"status\" lay-filter=\"stat1\">\n" +
                    "<option value='" + v.interviewId + "' disabled='disabled'>请选择</option>\n" +
                    "<option value=\"录用\" selected='selected' disabled='disabled'>录用</option>\n" +
                    "</select>\n" +
                    "</div>\n" +
                    "</div>";
                tiao = "<button type=\"button\" class=\"layui-btn\" onclick=\"messageById(" + v.resumeId + ")\">明细</button>";
            }
            $("#tal1").find("tr").eq(i + 1).find("td").eq(0).text((currentPage - 1) * pageSize + 1 + i);
            $("#tal1").find("tr").eq(i + 1).find("td").eq(1).text(v.name);
            $("#tal1").find("tr").eq(i + 1).find("td").eq(2).text(v.sex);
            $("#tal1").find("tr").eq(i + 1).find("td").eq(3).text(v.school);
            $("#tal1").find("tr").eq(i + 1).find("td").eq(4).text(v.educationBackground);
            $("#tal1").find("tr").eq(i + 1).find("td").eq(5).text(v.major);
            $("#tal1").find("tr").eq(i + 1).find("td").eq(6).text(v.positionName);
            $("#tal1").find("tr").eq(i + 1).find("td").eq(7).text(v.experience);
            $("#tal1").find("tr").eq(i + 1).find("td").eq(8).text(v.rTime);
            $("#tal1").find("tr").eq(i + 1).find("td").eq(9).html(xiala);
            $("#tal1").find("tr").eq(i + 1).find("td").eq(10).html(tiao);
        })

    })
    $.ajaxSettings.async = true;
    showPage();
    layui.use('form', function () {
        var form = layui.form;
        form.render();
    });
}

function check() {
    showInfo();
}

function next1() {
    currentPage++;
    if (currentPage > totalPage) {
        currentPage = totalPage;
        return;
    }
    showInfo()
}

function prev1() {
    currentPage--;
    if (currentPage < 1) {
        currentPage = 1;
        return;
    }
    showInfo()
}

function first1() {
    currentPage = 1;
    showInfo()
}

function end1() {
    currentPage = totalPage;
    showInfo()
}

function messageById(rId) {
    window.location.href = "/面试结果登记/" + rId;
}

function shanchu1(rId, thisA) {
    layer.confirm('确定要删除吗?', {icon: 3, title: '提示'}, function () {
        let jsonA = {
            interviewId: rId,
            status: "删除"
        }
        $.ajaxSettings.async = false;
        $.post("/save22", jsonA, function (dataA) {
            if (dataA > 0) {
                $(thisA).parents("tr").remove();
                layer.closeAll();
            } else {
                alert("删除失败！");
                return;
            }
        }, "JSON")
        $.ajaxSettings.async = true;
        if (totalCount % pageSize == 0) {
            currentPage = currentPage - 1;
        }
        showPage();
        showInfo1();
        layer.close();
    });
    showInfo1();
}

//////////////////////////////////////////////////////////////
//*********弹层********//

layui.use('form', function () {
    let form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功
    let time;
    form.on('select(b)', function (data) {
        abc = (data.value);

        let id = $(this).parent().parent().parent().find("option").eq(0).val()

        if (abc == "推荐二面") {
            layer.open({
                title: '一面面试结果登记'
                , content: '<table class="layui-table myTable3">\n' +
                    '        <tr>\n' +
                    '            <td>一面面试人：</td>\n' +
                    '            <td><input type="text" class="layui-input oneInterviewer" value="" readonly="readonly"></td>\n' +
                    '            <td>面试时间：</td>\n' +
                    '            <td><input type="text" class="layui-input oneTime" value="" readonly="readonly"></td>\n' +
                    '        </tr>\n' +
                    '        <tr>\n' +
                    '            <td width="20%">一面面试评价：</td>\n' +
                    '            <td colspan="3"> <textarea style="height: 60px"  style="height: 60px" class="layui-input oneOpinion" name="oneOpinion"></textarea></td>\n' +
                    '        </tr>\n' +
                    '    </table>',
                area: ['800px', '300px'],
                btn: ["确定", "取消"],

                success: function () {//弹出层弹出后回调
                    //当前日期赋值给时间
                    time = new Date().toLocaleDateString();
                    $(".oneTime").val(time);
                    $(".oneInterviewer").val(uus);

                    //取消esc
                    $('.layui-layer-setwin').hide();
                },
                btn1: function () {//确定事件

                    let oneInterviewer = $(".oneInterviewer").val().trim();
                    let oneOpinion = $(".oneOpinion").val().trim();

                    let jsonA = {
                        interviewId: id,
                        status: abc,
                        oneInterviewer: oneInterviewer,
                        oneTime: time,
                        oneOpinion: oneOpinion
                    }
                    $.ajaxSettings.async = false;
                    $.post("/save11", jsonA, function (dataA) {
                        if (dataA > 0) {
                            alert("结果登记成功！");
                            layer.closeAll();
                        } else {
                            alert("结果登记失败！");
                            return;
                        }
                    }, "JSON")
                    $.ajaxSettings.async = true;
                    showInfo1();
                },
                btn2: function () {//取消事件
                    showInfo1();
                }
            });
        } else if (abc == "推荐三面") {
            layer.open({
                title: '二面面试结果登记'
                , content: '<table class="layui-table myTable3">\n' +
                    '        <tr>\n' +
                    '            <td>二面面试人：</td>\n' +
                    '            <td><input type="text" class="layui-input twoInterviewer" value="" readonly="readonly"></td>\n' +
                    '            <td>面试时间：</td>\n' +
                    '            <td><input type="text" class="layui-input twoTime" readonly="readonly"></td>\n' +
                    '        </tr>\n' +
                    '        <tr>\n' +
                    '            <td width="20%">二面面试评价：</td>\n' +
                    '            <td colspan="3"> <textarea style="height: 60px"  class="layui-input twoOpinion" name="twoOpinion"></textarea></td>\n' +
                    '        </tr>\n' +
                    '    </table>',
                area: ['800px', '300px'],
                btn: ["确定", "取消"],
                success: function () {//弹出层弹出后回调
                    //赋值给时间
                    time = new Date().toLocaleDateString();
                    $(".twoTime").val(time);
                    $('.layui-layer-setwin').hide();
                    $(".twoInterviewer").val(uus);
                },
                btn1: function () {//确定事件
                    let twoInterviewer = $(".twoInterviewer").val().trim();
                    let twoOpinion = $(".twoOpinion").val().trim();

                    let jsonA = {
                        interviewId: id,
                        status: abc,
                        twoInterviewer: twoInterviewer,
                        twoTime: time,
                        twoOpinion: twoOpinion
                    }

                    $.ajaxSettings.async = false;
                    $.post("save12", jsonA, function (dataA) {

                        if (dataA > 0) {
                            alert("结果登记成功！");
                            layer.closeAll();
                        } else {
                            alert("结果登记失败！");
                            return;
                        }
                    }, "JSON");
                    $.ajaxSettings.async = true;
                    showInfo1();
                },
                btn2: function () {//取消事件
                    showInfo1();
                }
            });
        } else if (abc == "建议录用") {
            layer.open({
                title: '三面面试结果登记'
                , content: '<table class="layui-table myTable3">\n' +
                    '        <tr>\n' +
                    '            <td>三面面试人：</td>\n' +
                    '            <td><input type="text" class="layui-input threeInterviewer" value="" readonly="readonly"></td>\n' +
                    '            <td>面试时间：</td>\n' +
                    '            <td><input type="text" class="layui-input threeTime" readonly="readonly"></td>\n' +
                    '        </tr>\n' +
                    '        <tr>\n' +
                    '            <td width="20%">三面面试评价：</td>\n' +
                    '            <td colspan="3"> <textarea style="height: 60px"  class="layui-input threeOpinion" name="threeOpinion"></textarea></td>\n' +
                    '        </tr>\n' +
                    '    </table>',
                area: ['800px', '300px'],
                btn: ["确定", "取消"],
                success: function () {//弹出层弹出后回调
                    //赋值给时间
                    time = new Date().toLocaleDateString();
                    $(".threeTime").val(time);
                    $('.layui-layer-setwin').hide();
                    $(".threeInterviewer").val(uus);
                },
                btn1: function () {//确定事件
                    let threeInterviewer = $(".threeInterviewer").val().trim();
                    let threeOpinion = $(".threeOpinion").val().trim();

                    let jsonA = {
                        interviewId: id,
                        status: abc,
                        threeInterviewer: threeInterviewer,
                        threeTime: time,
                        threeOpinion: threeOpinion
                    }

                    $.ajaxSettings.async = false;
                    $.post("save13", jsonA, function (dataA) {
                        if (dataA > 0) {
                            alert("结果登记成功！");
                            layer.closeAll();
                        } else {
                            alert("结果登记失败！");
                            return;
                        }
                    }, "JSON")
                    $.ajaxSettings.async = true;
                    showInfo1();
                },
                btn2: function () {//取消事件
                    showInfo1();
                }
            });
        }
    })
})
